﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AvatarHelper;
using Avatar.Model;

namespace Avatar.MembershipService
{

    public static class UserManager
    {
        /// <summary>
        /// 根据关键词在用户Email地址中搜索
        /// </summary>
        /// <param name="_keyWord"></param>
        /// <returns></returns>
        public static List<Avatar_User> SearchUserByEmail(string _keyWord)
        {
            if (string.IsNullOrEmpty(_keyWord)) throw new Exception("关键词不能为空");

            var _list = DBHelper.GetAll<Avatar_User>(u => u.Email.IndexOf(_keyWord) >= 0, "获取用户列表出错:");

            if (_list.Count > 10) throw new Exception("搜索结果过多，请提供更精确的关键词、缩小查询范围");

            return _list;
        }

        /// <summary>
        /// 根据关键词在用户名中搜索
        /// </summary>
        /// <param name="_keyWord"></param>
        /// <returns></returns>
        public static List<Avatar_User> SearchUserByKeyWord(string _keyWord)
        {
            if (string.IsNullOrEmpty(_keyWord)) throw new Exception("关键词不能为空");

            var _list = DBHelper.GetAll<Avatar_User>(u => u.Name.IndexOf(_keyWord) >= 0, "获取用户列表出错:");

            if (_list.Count > 10) throw new Exception("搜索结果过多，请提供更精确的关键词、缩小查询范围");

            return _list;
        }
    }
}
